﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using IDAL;
using Model;

namespace DAL
{
    public class TestItem_PP : BaseRepository<ProductType_QInfo>, ITestItem_PP
    {
        #region 静态变量定义部分
        private const string PARM_TEST_PRODUCTTYPEID = "@ProductTypeID";
        private const string PARM_TEST_TIMEDAY = "@DayTime";
        private const string PARM_TEST_STARTTIME = "@starttime";
        private const string PARM_TEST_STOPTIME = "@stoptime";
        #endregion

        #region 数据检索部分
        protected IList<ProductType_QInfo> GetPID_Time(string spname, string productTypeID, string dayTime)
        {
            SqlParameter[] testParms = GetDayParameters();
            testParms[0].Value = productTypeID;
            testParms[1].Value = dayTime;
            return ExcuteSqlToGetEntities(spname, testParms);
        }

        protected IList<ProductType_QInfo> GetPID_Time2(string spname, string dayTime)
        {
            SqlParameter testParms = new SqlParameter(PARM_TEST_TIMEDAY, SqlDbType.NVarChar, 50);
            testParms.Value = dayTime;
            return ExcuteSqlToGetEntities(spname, testParms);
        }

        
        public IList<ProductType_QInfo> GetDayPID_PP(string productTypeID, string dayTime)
        {
            return GetPID_Time("TestItem_PercentPointbyPID_Day", productTypeID, dayTime);
        }

        public IList<ProductType_QInfo> GetMonthPID_PP(string productTypeID, string dayTime)
        {
            return GetPID_Time("TestItem_PercentPointbyPID_Month", productTypeID, dayTime);
        }

        public IList<ProductType_QInfo> GetDayPID_EI(string productTypeID, string dayTime)
        {
            return GetPID_Time("TestItem_EightItemsbyPID_Day", productTypeID, dayTime);
        }

        public IList<ProductType_QInfo> GetMonthPID_EI(string productTypeID, string dayTime)
        {
            return GetPID_Time("TestItem_EightItemsbyPID_Month", productTypeID, dayTime);
        }

        public IList<ProductType_QInfo> GetDay_EI(string dayTime)
        {
            return GetPID_Time2("TestItem_EightItemsbyDay", dayTime);
        }

        public IList<ProductType_QInfo> GetMonth_EI(string dayTime)
        {
            return GetPID_Time2("TestItem_EightItemsbyMonth", dayTime);
        }

        public IList<ProductType_QInfo> GetDTPID_PP(string pID, DateTime dt1,DateTime dt2)
        {
            SqlParameter[] testParms = GetDTParameters();
            testParms[0].Value = pID;
            testParms[1].Value = dt1;
            testParms[2].Value = dt2;
            return ExcuteSqlToGetEntities("TestItem_PercentPointbyPID_DT", testParms);
        }
        #endregion

        #region 参数部分
        private static SqlParameter[] GetDayParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_TEST_PRODUCTTYPEID, SqlDbType.NVarChar, 50),
					new SqlParameter(PARM_TEST_TIMEDAY, SqlDbType.NVarChar, 50)                
                };
            return parms;
        }

        private static SqlParameter[] GetDTParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
                    new SqlParameter(PARM_TEST_PRODUCTTYPEID, SqlDbType.NVarChar, 50),
					new SqlParameter(PARM_TEST_STARTTIME, SqlDbType.DateTime, 8),
					new SqlParameter(PARM_TEST_STOPTIME, SqlDbType.DateTime, 8)                
                };
            return parms;
        }
        #endregion

        //-------------------------------------重写超类基础操作---------------------------------------------------------

        public override ProductType_QInfo GetEntityRecord(SqlDataReader rdr)
        {
            ProductType_QInfo pro = new ProductType_QInfo(rdr.GetValue(0).ToString(), rdr.GetDecimal(1), rdr.GetInt32(2), rdr.GetInt32(3));
            return pro;
        }
    }
}
